home *** CD-ROM | disk | FTP | other *** search
- #include <FixMath.h>
- #include "QD3DtoQTVR.h"
- #include "extern.h"
- #include "camera.h"
-
- TQ3CameraObject MyNewCamera(CWindowPtr theWindow)
- {
- TQ3ViewAngleAspectCameraData perspectiveData;
- TQ3CameraObject camera;
- // Set the field of view to 30 degrees (or 30*kQ3Pi/180 radians).
- float fieldOfView = .52359333333;
- TQ3Status returnVal = kQ3Failure ;
-
- // Assign default placement and range
- perspectiveData.cameraData.placement.cameraLocation = kMyDefaultFrom;
- perspectiveData.cameraData.placement.pointOfInterest = kMyDefaultTo;
- perspectiveData.cameraData.placement.upVector = kMyDefaultUp;
- perspectiveData.cameraData.range.hither = kMyDefaultHither;
- perspectiveData.cameraData.range.yon = kMyDefaultYon;
-
- // Assign standard viewport
- perspectiveData.cameraData.viewPort.origin.x = -1.0;
- perspectiveData.cameraData.viewPort.origin.y = 1.0;
- perspectiveData.cameraData.viewPort.width = 2.0;
- perspectiveData.cameraData.viewPort.height = 2.0;
-
- perspectiveData.fov = fieldOfView;
- perspectiveData.aspectRatioXToY =
- (float) (theWindow->portRect.right - theWindow->portRect.left) /
- (float) (theWindow->portRect.bottom - theWindow->portRect.top);
-
- camera = Q3ViewAngleAspectCamera_New(&perspectiveData);
-
- return camera ;
- }
-
-
- void MyGetBoundingSphere(TQ3ViewObject viewObject, TQ3GroupObject mainGroup, TQ3BoundingSphere *viewBSphere)
- {
- TQ3Status status;
-
- Q3View_StartBoundingSphere(viewObject,kQ3ComputeBoundsApproximate);
- do {
- status = Q3DisplayGroup_Submit(mainGroup, viewObject);
- } while (Q3View_EndBoundingSphere(viewObject, viewBSphere) == kQ3ViewStatusRetraverse);
- }
-
-
- void MyInitObjCamera(DocumentPtr theDocument)
- {
- TQ3BoundingSphere viewBSphere;
- float viewRadius;
-
- if(theDocument == NULL)
- return;
-
- // Get the bounding sphere of the drawable group (the entire model) in the view.
- MyGetBoundingSphere(theDocument->theView, theDocument->documentGroup, &viewBSphere);
-
- // Get the bounding sphere's center and radius
- theDocument->documentGroupCenter = viewBSphere.origin;
- viewRadius = viewBSphere.radius;
-
- // position camera down z axis from bounding sphere based on center and radius
- MyPlaceCamera(theDocument, theDocument->documentGroupCenter.x,theDocument->documentGroupCenter.y,
- theDocument->documentGroupCenter.z + kMyDistanceFactor*viewRadius + 1.0,
- theDocument->documentGroupCenter.x,theDocument->documentGroupCenter.y,
- theDocument->documentGroupCenter.z + kMyDistanceFactor*viewRadius);
- }
-
-
- void MyPlaceCamera(DocumentPtr theDocument, float fromX,float fromY,float fromZ,
- float toX,float toY,float toZ)
- {
- TQ3CameraObject camera;
- TQ3CameraPlacement cameraPos;
-
- Q3View_GetCamera(theDocument->theView, &camera );
- Q3Camera_GetPlacement(camera, &cameraPos);
-
- cameraPos.cameraLocation.x = fromX;
- cameraPos.cameraLocation.y = fromY;
- cameraPos.cameraLocation.z = fromZ;
-
- cameraPos.pointOfInterest.x = toX;
- cameraPos.pointOfInterest.y = toY;
- cameraPos.pointOfInterest.z = toZ;
-
- Q3Camera_SetPlacement(camera, &cameraPos);
- Q3View_SetCamera(theDocument->theView, camera );
- Q3Object_Dispose(camera);
- }
-
-
-
-
-